<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      >
<head th:replace="fragments/tabhead::headc"></head>
<body>

<th:block layout:fragment="content">

<div style="margin-top:10px;">
  <form class="layui-form search" id="searchForm">
  <div class="layui-form-item layui-elem-quote">
     <div class="layui-inline">
      <label class="layui-form-label" style="width:120px">请选择公司</label>
      <div class="layui-input-inline">
        <select name="companyId">
        	<option value="">请选择公司</option>
        	<option th:each="s:${actCenterCompanyMap}" th:attr="value=${s.id}" th:text="${s.name}"></option>
        </select>
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label" style="width:120px">电话号码</label>
      <div class="layui-input-inline" style="width:120px">
        <input type="tel" name="phone" class="layui-input"/>
      </div>
    </div>
    <div class="layui-inline">
      <div class="layui-input-inline" style="width:80px;">
        <button class="layui-btn" id="searchBtn" type="button" authcode="900078">查询</button>
      </div>
    </div>
    <!-- 
    <div class="layui-inline">
      <div class="layui-input-inline" style="width:80px;">
        <button class="layui-btn" id="createBtn" type="button">新增</button>
      </div>
    </div>
    -->
  </div>
 </form>
</div>
    <table class="layui-table"  id="tab" lay-filter="tab"></table>
    
<script>
var ins,page,trobj,editdialogindex,data;
$(function(){ 
	
	layui.use(['table','layer'], function(){
		var table = layui.table;
		ins =table.render({ //其它参数在此省略
		 elem:"#tab",
		 url: '/act/center/sms/log/data',
		 cols:[[
			  {field:'id',width:100, sort: true,title:'Id',fixed:'left'},
		      {field:'companyName', width:200,title:'企业名称'},
		      {field:'phone', width:130, sort: true,title:'电话号码'},
		      {field:'content', width:270,title:'内容'},
		      {width:160,field:'fee',title:'费用(分)',templet: '#fee'},
		      {field:'send_time', width:200,title:'发送时间'},
		      {field:'status', width:150,title:'发送状态'},
		 ]]
	    ,page: true //是否显示分页
	    ,limits: [10,20,50]
	    ,limit:10 //每页默认显示的数量
		  //where:{phone:phone}
		  //method: 'post'
		 ,done:function(res,curr,count){
			 console.log(res);
			 page = curr;
			    //得到当前页码
			    console.log(curr); 
			    
			    //得到数据总量
			    console.log(count);
		 }
		});
		
		table.on("tool(tab)",function(obj){
			data = obj.data; //获得当前行json数据
			var layEvent = obj.event; //获得 lay-event 对应的值
			trobj = obj;
			var tr = obj.tr; //获得当前行 tr 的DOM对象
			console.log(data.id);
			if(layEvent=='edit'){
				$.post('/act/center/sms/log/edit', {"companyId":1,"id":data.id}, function(str){
				editdialogindex = layer.open({
									title:"修改",
								    type: 1,
								    zIndex:10,
								    area: ['810px', '630px'],
								    content: str //注意，如果str是object，那么需要字符拼接。
								  });
								});
			}else if(layEvent=='detail'){
				$.post('/act/center/sms/log/detail/', {"id":data.id}, function(str){
			          editdialogindex = layer.open({
			            title:"明细",
			              type: 1,
			              zIndex:10,
			              area: ['800px', '500px'],
			              content: str //注意，如果str是object，那么需要字符拼接。
			            });
			          });
			}else if(layEvent=='del'){
				layer.confirm('真的删除行么', function(index){
			        layer.close(index);
				$.post('/act/center/sms/log/del_execute', {"id":data.id}, function(str){
									if(str.code==200){
										layer.msg('删除成功！', {icon: 6});
										reloadData();
									}else{
										layer.msg('删除失败！', {icon: 5});
									}
									});
				});
			}
		});
		function reloadData(){ 
			$(".layui-laypage-btn")[0].click();
		}
		
		$("#createBtn").click(function(){
			$.post('/act/center/sms/log/edit', {"companyId":1,"id":""}, function(str){
				editdialogindex = layer.open({
									title:"新增",
								    type: 1,
								    zIndex:10,
								    area: ['850px', '600px'],
								    content: str //注意，如果str是object，那么需要字符拼接。
								  });
								});
		});
		
		$("#searchBtn").click(function(){
			var table = layui.table;
		    ins.reload({url: '/act/center/sms/log/data',where:$("#searchForm").serializeJson()});
		});
	})
	
	layui.use("laydate",function(){
		var laydate = layui.laydate;
		laydate.render({
			  elem: '#startDate' //指定元素
			});
		laydate.render({
			  elem: '#endDate' //指定元素
			});
	});
	
	

}); 
</script>
<script type="text/html" id="fee">
	{{d.fee/100}}
</script>
<script type="text/html" id="toolbar">
</script>

</th:block>



</body>
</html>